<?php Temp::Tinclude("commom/admin_header");?>
 <div class="padding_left_right">
<div class="panel panel-default">
    <div class="panel-heading"><span class="glyphicon glyphicon-list-alt"></span>订单号:<b class="text-danger"><?php echo $order["order_no"];?></b></div>
  <div class="panel-body">
  <ul class="list-group">
      <li class="list-group-item"><span class="glyphicon glyphicon-usd"></span>结算金额:<span class="text-success"><span id="jiesuan"><?php echo $order["sale_price"];?></span>元</span></li>
  <li class="list-group-item"><span class="glyphicon glyphicon-copyright-mark"></span>总重:<span class="text-primary"><span id="zhongliang"><?php echo $order["sale_weight"];?></span>斤</span></li>
  <li class="list-group-item"><span class="glyphicon glyphicon-user"></span>收货人:<span class="text-warning"><?php echo $order["user_name"];?></span></li>
  <li class="list-group-item"><span class="glyphicon glyphicon-phone"></span>收货人手机号码:<span class="text-warning"><?php echo $order["user_phone"];?></span></li>
  <li class="list-group-item"><span class="glyphicon glyphicon-plane"></span>收货人地址:<span class="text-warning"><?php echo $order["user_address"];?></span></li>
  <li class="list-group-item"><span class="glyphicon glyphicon-calendar"></span>下单日期:<span class="text-primary"><?php echo date("Y-m-d",$order["create_time"]);?></span></li>
</ul>
      
      <div class="jphidden">
      <?php if(isset($order_item)){?>
      <?php foreach($order_item as $v){?>
  <div class="media">
  <div class="media-left">
      <a target="_blank" href="/?Home/detail&gid=<?php echo $v["good_id"];?>">
      <img class="media-object" src="<?php echo Common::getThumb($v["good_image"],"50x50");?>" alt="">
    </a>
  </div>
  <div class="media-body">
     <h4 class="media-heading"><?php echo $v["good_name"];?></h4>
    <div class="col-md-3 col-xs-12">
    <div class="input-group">
  <span class="input-group-addon">价格：</span>
  <input type="text" data-price="<?php echo $v["sale_price"];?>"  value="<?php echo $v["sale_price"];?>" data-vid="<?php echo $v["id"];?>" class="form-control jgs" placeholder="价格"/>
  <span class="input-group-addon">(元/斤)</span>
    </div>
    </div>
 <div class="col-md-3 col-xs-12">
     <div class="input-group">
  <span class="input-group-addon">重量：</span>
  <input type="text" class="form-control zls" data-weight="<?php echo $v["sale_weight"];?>"  placeholder="重量" data-vid="<?php echo $v["id"];?>" value="<?php echo $v["sale_weight"];?>"  />
  <span class="input-group-addon">(斤)</span>
    </div>
 </div>
     
     <div class="col-md-3 col-xs-12">
        <button type="button" class="btn btn-danger deletbtn" data-itid="<?php echo $v["id"];?>"><span class="glyphicon glyphicon-trash"></span>移除</button>
    </div>
     
  </div>
</div>
      <?php }?>
      <?php }?>
      </div> 
      
      
      <table class="table table-condensed jpshow" style="display: none;">
          <thead>
        <tr>
          <th class="text-center">名称</th>
          <th class="text-center">价格</th>
          <th class="text-center">重量</th>
          <th class="text-center">小计</th>
        </tr>
      </thead>
      <tbody>
          
           <?php if(isset($order_item)){?>
      <?php foreach($order_item as $v){?>
      <tr class="tableitem_<?php echo $v["id"];?>">
       <td class="text-center"><?php echo $v["good_name"];?></td>
       <td class="text-center"><span class="sale_price_<?php echo $v["id"];?>"><?php echo $v["sale_price"];?></span>(元/斤)</td>
       <td class="text-center"><span class="sale_weight_<?php echo $v["id"];?>"><?php echo $v["sale_weight"];?></span>(斤)</td>
       <td class="text-center"><span class="xiaoji_<?php echo $v["id"];?>"><?php echo $v["sale_weight"]*$v["sale_price"];?></span>(元)</td>
      </tr>
       <?php }?>
      <?php }?>
          
      </tbody>
          
      </table>
      
      
  </div>
</div>
     
      <div class="jphidden">
     <button type="button"  class="btn btn-primary btn-block" id="print"><span class="glyphicon glyphicon-print"></span>打印</button>
      </div>
 </div>

<script>
    $(".deletbtn").click(function(){
        var id=$(this).data("itid");
        $(this).parent().parent().parent().remove();
        $(".tableitem_"+id).remove();
        jisuanzongjia();  
        jisuanzongzhong();
        $.post("/?order/public_ajax_delete_order_item",{"id":id},function(data){
          if(data.status==1){
              
          }
      },"json");
    });
    $("#print").click(function(){
        $(".jpshow").show();
        $(".jphidden").hide();
        javascript:window.print();
        $(".jphidden").show();
         $(".jpshow").hide();
    });
    $(".jgs").blur(function(){
      var id=$(this).data("vid");
      var jg=parseFloat($(this).val());
        if(isNaN(jg)){
             alert("请输入正确的价格");
             $(this).val($(this).data("price"));
             $(this).focus();
             return false;
         }else if(jg==0){
             alert("请输入价格");
             $(this).focus();
             return false;
         }
      jisuanzongjia();  
      jisuanzongzhong();
      $.post("/?order/public_ajax_update_order_item",{"id":id,"sale_price":jg},function(data){
          if(data.status==1){
              
          }
      },"json");
    });
    $(".zls").blur(function(){
       var id=$(this).data("vid");
       var zl=parseFloat($(this).val());
       if(isNaN(zl)){
             alert("请输入正确的重量");
              $(this).val($(this).data("weight"));
             $(this).focus();
             return false;
         }else if(zl==0){
             alert("请输入重量");
             $(this).focus();
             return false;
         }
        
       jisuanzongjia();   
       jisuanzongzhong();
       $.post("/?order/public_ajax_update_order_item",{"id":id,"sale_weight":zl},function(data){
          if(data.status==1){
              
          }
      },"json");
    });
    
    
    function jisuanzongjia(){
        var zongjia=0.0;
        $(".jgs").each(function(){
            var jg=parseFloat($(this).val());
            var id=$(this).data("vid");
            var zl=parseFloat($(this).parent().parent().parent().find(".zls").val());
            var xiaoji=jg*zl;
            zongjia+=xiaoji;
            $(".xiaoji_"+id).html(xiaoji.toFixed(2));
            $(".sale_price_"+id).html(jg.toFixed(2));
            $(".sale_weight_"+id).html(zl.toFixed(2));
            
        });
        $("#jiesuan").html(zongjia.toFixed(2));
    }
    function jisuanzongzhong(){
        var zongzhong=0.0;
        $(".zls").each(function(){
            var zl=parseFloat($(this).val());
            zongzhong+=zl;
            
            
        });
        $("#zhongliang").html(zongzhong.toFixed(2));
    }
    
</script>
<?php Temp::Tinclude("commom/admin_footer");?>